home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Print.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  14.5 KB  |  451 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Print.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.0.5+>    11/19/93    NAGA        modify TCS format
  19. #     <1.0.5>     8/25/93    KTA        Added support for parity checking the TCS stack.
  20. #     <1.0.4>     7/19/93    KTA        Updates for FindWindow() to handle descriptors.
  21. #     <1.0.3>     7/14/93    KTA        International Support: See Printer(), and PageSetUp().
  22. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  23. #
  24. # ****************************************************************************
  25. #
  26.  
  27. ########################################################################
  28. #                            External libraries 
  29. #=======================================================================
  30. Libraries "Output.Lib","TCS.Lib","UserInterface.Lib";
  31.  
  32. #########################################################################
  33. #                            PageSetup.lib
  34. #========================================================================
  35. # Description:    This file contains Task to test the page setup dialog.
  36. #                Currently only TestPageSetup() should be called. The
  37. #                other Tasks are support for this Task.
  38. #
  39. #            Tasks:
  40. #                TestPageSetup(checkBoxTest,paperSizeTest,pageSizeTest,orientationTest,printTest)
  41. #                TestCheckBoxList(checkBoxList)
  42. #                PaperSize()
  43. #                PageSize()
  44. #                ToggleOrientation()
  45. #                PrintSample()
  46. #
  47. #     Copyright Apple Computer, Inc. 1985-1990
  48. #    All rights reserved
  49. #========================================================================
  50. #     ECH        11/29/90        Created
  51. #########################################################################
  52.  
  53.  
  54. #########################################################################
  55. #    TestPageSetup(checkBoxTest,paperSizeTest,pageSizeTest,orientationTest,printTest)
  56. #========================================================================
  57. # Author:        Eric Hewitt
  58. # Description:    Tests the standard page setup.  All permutations of 
  59. #                checkboxes, paper radio buttons, scale controls, and 
  60. #                orientation icons are selected.  
  61. # Parameters:    checkBoxTest -    0 = do not test checkboxes
  62. #                                    1 = test check boxes
  63. #                paperSizeTest -    0 = do not test paper sizes
  64. #                                1 = test paper sizes
  65. #                pageSizeTest -    0 = do not test page sizes
  66. #                                1 = test page sizes
  67. #                orientationTest -    0 = do not test orientation
  68. #                                    1 = test orientation
  69. #                printTest -    0 = do not print after each combination
  70. #                            1 = perform print test after each combination
  71. # Returns:        0 = Error occured in testing
  72. #                1 = Successful test
  73. # Examples:        TestPageSetup(1,0,0,1,0);
  74. # Assumptions:    A Page Setup dialog is up.
  75. #========================================================================
  76. # History:
  77. #
  78. #########################################################################
  79. TASK TestPageSetup(checkBoxTest := 1,paperSizeTest := 1,pageSizeTest := 1,orientationTest := 1,printTest := 0)
  80. begin
  81.     (*    ** Sample Printer Entry **
  82.     Parameters := {    Printer Name,
  83.                     list of check box names,
  84.                     list of paper size radio button names,
  85.                     list of page size radio button names, 
  86.                         or 0 if size is a text entry field
  87.                         or if page size is changed by up and down controls, a list
  88.                            with first element = # of possible values and the next
  89.                            two = location of controls,
  90.                     location of portrait orientation control relative to the window,
  91.                     location of lanscape orientation control relative to the window
  92.                   };
  93.     *)
  94.     PrinterList := {
  95.             {    'LaserWriter Page Setup',
  96.                 { 'Font Substitution?','Text Smoothing?','Graphics Smoothing?','Faster Bitmap Printing?' },
  97.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','' },
  98.                 0,                                # Text field
  99.                 { 80,135 },
  100.                 { 115,135 } 
  101.             },
  102.             {    'Personal LaserWriter LS',
  103.                 { 'Precision Bitmap Alignment' },
  104.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','No. 10 Envelope' },
  105.                 { '100%','75%','50%' },
  106.                 { 40,120 },
  107.                 { 80,120 }
  108.             },
  109.             {    'Personal LaserWriter SC',
  110.                 { 'Exact Bit Images (Shrink 4%)','Text Smoothing' },
  111.                 { 'US Letter','US Legal','A4 Letter','B5 Letter','No. 10 Envelope' },
  112.                 { '100%','75%','50%' },
  113.                 { 30,115 },
  114.                 { 70,115 }
  115.             },
  116.             {    'Tabasco',
  117.                 { },
  118.                 { 'US Letter','US Legal','A4 Letter','Envelope (#10)' },
  119.                 { 5,{ 317,93 },{ 317,83 } },    # up and down controls
  120.                 { 120,100 },
  121.                 { 160,100 }
  122.             }
  123.     };
  124.     
  125.     ### Check to see if the page setup dialog is for a known printer
  126.     for i := 1 to card printerList
  127.         if (match [staticText t:printerList[i][1]]!)
  128.         begin
  129.             printerName := printerList[i][1];
  130.             global printerParameters := printerList[i];
  131.             global testCheckBoxes := checkBoxTest;
  132.             global testPaperSize := paperSizeTest;
  133.             global testPageSize := pageSizeTest;
  134.             global testOrientation := orientationTest;
  135.             global testPrint := printTest;
  136.             LogStr("====================================================================");
  137.             LogStr("Testing PageSetup for {printerName}");
  138.             ### First excercise the checkboxes, then paper size radio buttons, page 
  139.             ### size controls, and orientation controls.
  140.             TestCheckBoxList(printerList[i][2]);
  141.              
  142.             ### excercise help
  143.             if (match [button t:'Help']!)
  144.             begin
  145.                 LogStr("Testing Help");
  146.                 if (SelectButton('Help'))
  147.                 begin
  148.                     wait(2);
  149.                     SelectButton('OK');
  150.                 end;
  151.             end;
  152.             
  153.             ### successful test
  154.             return(1);
  155.         end;
  156.  
  157.     ### No match on any of the known printers
  158.     LogStr("*** Unknown Printer type ***");
  159.     return(0);
  160. end;
  161.     
  162.  
  163. #########################################################################
  164. #                    TestCheckBoxList(printerParameters)
  165. #========================================================================
  166. # Author:        Eric Hewitt
  167. # Description:    Selects all possible combinations of check boxes by
  168. #                recursive calls to itself.  After each combination, it
  169. #                calls PaperSize() which will result in all possible
  170. #                combinations of check boxes, paper sizes, page sizes, and
  171. #                orientations.
  172. # Parameters:    checkBoxList -    A list of check box names
  173. # Returns:        Nothing
  174. #========================================================================
  175. # History:
  176. #
  177. #########################################################################
  178. TASK TestCheckBoxList(checkBoxList)
  179. begin
  180.     if (global testCheckBoxes)
  181.     begin
  182.         if (card checkBoxList = 0)
  183.         begin
  184.             PaperSize();
  185.             return(0);
  186.         end;
  187.         else
  188.             for a := 1 to 2
  189.             begin
  190.                 TestCheckBoxList(remove(1,checkBoxList));
  191.                 SelectCheckBox(checkBoxList[1]);
  192.             end;
  193.     end;
  194.     else
  195.         PaperSize();
  196. end;
  197.  
  198.  
  199. #########################################################################
  200. #                            PaperSize()
  201. #========================================================================
  202. # Author:        Eric Hewitt
  203. # Description:    Selects all the paper size radio buttons.  After selecting
  204. #                each button, it calls PageSize() to go through all possible
  205. #                page sizes and then orientations.  This exercises all
  206. #                possible combinations of paper size, page size, and 
  207. #                orientation.
  208. # Parameters:    None
  209. # Returns:        Nothing
  210. #========================================================================
  211. # History:
  212. #
  213. #########################################################################
  214. TASK PaperSize()
  215. begin
  216.     global printerParameters;
  217.     
  218.     if (global testPaperSize)
  219.     begin
  220.         for a := 1 to card printerParameters[3]
  221.         begin
  222.             SelectRadioButton(printerParameters[3][a]);
  223.             PageSize();
  224.         end;
  225.     end;
  226.     else
  227.         PageSize();
  228. end;
  229.  
  230.  
  231. #########################################################################
  232. #                                PageSize()
  233. #========================================================================
  234. # Author:        Eric Hewitt
  235. # Description:    Selects the paper size in one of either three ways: Typing
  236. #                values in a text edit field, selecting an up and down 
  237. #                control, or by selecting radio buttons.  In between each
  238. #                page size, this function calls ToggleOrientation.
  239. # Parameters:    None
  240. # Returns:        Nothing
  241. #========================================================================
  242. # History:
  243. #
  244. #########################################################################
  245. TASK PageSize()
  246. begin
  247.     global printerParameters;
  248.     
  249.     if (global testPageSize)
  250.     begin
  251.         if (printerParameters[4] = 0)
  252.         begin
  253.             ### Text entry field so type in values 100,80,60,40,20
  254.             for b := 100 to 20 step -20
  255.             begin
  256.                 # erase old value
  257.                 type k:{ backspacekey,backspacekey,backspacekey };
  258.                 # type in new value
  259.                 TypeStr("{b}");
  260.                 # Change orientation
  261.                 ToggleOrientation();
  262.             end;
  263.         end;
  264.         else if (TypeOf(printerParameters[4][1]) = 'integer')
  265.         begin
  266.             ### Up and down arrow controls to select size
  267.             for b := 1 to printerParameters[4][1]
  268.             begin
  269.                 # Select down control
  270.                 temp := global gDisableAllLogging;
  271.                 global gDisableAllLogging := 1;
  272.                 MoveRelativeToWindow(printerParameters[4][2][1],printerParameters[4][2][2],1,2);
  273.                 global gDisableAllLogging := temp;
  274.                 LogStr("Pressed scale down control");
  275.                 ToggleOrientation();
  276.             end;
  277.             for b := 1 to printerParameters[4][1]
  278.             begin
  279.                 # reset control by selecting up
  280.                 temp := global gDisableAllLogging;
  281.                 global gDisableAllLogging := 1;
  282.                 MoveRelativeToWindow(printerParameters[4][3][1],printerParameters[4][3][2],1,2);
  283.                 global gDisableAllLogging := temp;
  284.                 LogStr("Pressed scale up control");
  285.             end;
  286.         end;
  287.         else
  288.             ### There are radio buttons to select size
  289.             for b := 1 to card printerParameters[4]
  290.             begin
  291.                 SelectRadioButton(printerParameters[4][b]);
  292.                 ToggleOrientation();
  293.             end;
  294.     end;
  295.     else
  296.         ToggleOrientation();
  297. end;
  298.  
  299.  
  300. #########################################################################
  301. #                    ToggleOrientation()
  302. #========================================================================
  303. # Author:        Eric Hewitt
  304. # Description:    Toggles the portrait and landscape icons.
  305. # Parameters:    None
  306. # Returns:        Nothing
  307. # Examples:        ToggleOrientation();
  308. #========================================================================
  309. # History:
  310. #
  311. #########################################################################
  312. TASK ToggleOrientation()
  313. begin
  314.     global printerParameters;
  315.     
  316.     if (global testOrientation)
  317.     begin
  318.         temp := global gDisableAllLogging;
  319.         global gDisableAllLogging := 1;
  320.         MoveRelativeToWindow(printerParameters[5][1],printerParameters[5][2],1,2);
  321.         global gDisableAllLogging := 0;
  322.         LogStr("Pressed Portrait control");
  323.         PrintSample();
  324.         global gDisableAllLogging := 1;
  325.         MoveRelativeToWindow(printerParameters[6][1],printerParameters[6][2],1,2);
  326.         global gDisableAllLogging := temp;
  327.         LogStr("Pressed Landscape control");
  328.         PrintSample();
  329.     end;
  330. end;
  331.  
  332.  
  333. #########################################################################
  334. #                    PrintSample()
  335. #========================================================================
  336. # Author:        Eric Hewitt
  337. # Description:    Prints the current document and then reopens the pagesetup
  338. #                dialog.
  339. # Parameters:    None
  340. # Returns:        Nothing
  341. # Examples:        PrintSample();
  342. #========================================================================
  343. # History:
  344. #
  345. #########################################################################
  346. TASK PrintSample()
  347. begin
  348.     if (global testPrint)
  349.     begin
  350.         SelectButton('OK');                            # close page setup dialog
  351.         
  352.         ### Remember front window
  353.         frontWindow := match [window o:1]!;
  354.         
  355.         if (SelectMenuItem('Print','File'))
  356.         begin
  357.             SpecialKey(returnKey,"Return Key");        # close print dialog
  358.             LogStr("Printing Document");
  359.         end;
  360.         
  361.         ### Wait for frontWind to become the front window again
  362.         while not (match [window o:1 t:frontWindow.t]!);
  363.         
  364.         if not (SelectMenuItem('Page Setup','File'))
  365.         begin
  366.             LogStr("#### ERROR: Could not open page setup. Exiting script");
  367.             exit;
  368.         end;
  369.     end;
  370. end;
  371.  
  372. #########################################################################
  373. #                    PrintAlert() 
  374. #========================================================================
  375. # Author:            Eric Hewitt
  376. # Description:        Logs the Static text from an alert dialog.
  377. # Parameters:        none
  378. # Return Values:    none
  379. # Examples:            PrintAlert();
  380. #========================================================================
  381. # History:
  382. #
  383. #########################################################################
  384. TASK PrintAlert()
  385. begin
  386.     messages := collect [staticText w:[window o:1]];
  387.     if (card messages > 0)
  388.     begin
  389.         first := messages[1].t;
  390.         LogStr("!@#$% ALERT: {first}");
  391.     end;
  392.     if (card messages > 1)
  393.     begin
  394.         second := messages[2].t;
  395.         LogStr("!@#$% ALERT: {second}");
  396.     end;
  397. end;
  398.  
  399. ########################################################################
  400. #                        PageSetup( WhichDevice )
  401. #=======================================================================
  402. # Author:             KTA
  403. # Description:        For PageSetup routines
  404. # Parameters:        WhichDevice - device
  405. #                    PagSetupMI - pageSetup menuItem descriptor
  406. # Returns:            None
  407. #=======================================================================
  408. # History:
  409. # KTA    7/8/93    International support: Pass in PageSetup menuItem descriptor
  410. # KTA    7/19/93    changed descriptor so it is not embedded in a list
  411. # KTA    8/24/93    TCS stack parity check
  412. ########################################################################
  413. TASK PageSetup(WhichDevice := "LaserWriter", PagSetupMI := {"Page Setup", "File"}) 
  414. begin
  415.     if ( WhichDevice = "LaserWriter")
  416.     begin
  417.         TCSStart({ 1, global kTCSetPageSetup },"Select 'Page Setup'");
  418.         TCSEnd({ 1, global kTCSetPageSetup }, SelectMenuItem(PagSetupMI[1], PagSetupMI[2]));    #To select Page SetUp…
  419.         wait(1);
  420.         PageSetupDesc:= match[window o:1]!;
  421.         TCSStart({ 2, global kTCSetPageSetup },"Dismiss the Page Setup Dialog");
  422.         SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  423.         wait(1);
  424.         if not FindWindow(PageSetupDesc)
  425.             TCSEnd({ 2, global kTCSetPageSetup },1);
  426.         else
  427.             TCSEnd({ 2, global kTCSetPageSetup },0);
  428.     end;
  429. end; # PageSetup()
  430.  
  431. ########################################################################
  432. #                        Print()
  433. #=======================================================================
  434. # Author:             KTA
  435. # Description:        For Print routines
  436. # Parameters:        PrintMI - menuItem descriptor
  437. # Returns:            None
  438. #=======================================================================
  439. # History:
  440. # KTA    7/8/93    International Support: Pass in MenuItem descriptor
  441. ########################################################################
  442. TASK Printer(PrintMI := {"Print", "File"}) 
  443. begin
  444.     if     (global PrintTest)
  445.     begin
  446.         SelectMenuItem(PrintMI[1], PrintMI[2]);        #To select Print
  447.         wait(2);
  448.         SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  449.     end;
  450. end; # Printer()
  451.